package cn.zwxky.android.staff.My;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.config.Config;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.SN;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cn.zwxky.android.staff.R;
import cn.zwxky.android.staff.Utils.LittleUtils;
import cn.zwxky.android.staff.Utils.URLString;


/**
 * 系统消息页面
 * Created by Administrator on 2017/3/15 0015.
 */
@ContentView(R.layout.aty_system_msg)
public class SystemMsgActivity extends LsfbActivity {

    /**
     * RecyclerView的布局管理器
     */
    private RecyclerView.LayoutManager mlayoutManager;

    /**
     * 适配器
     */
    private SystemMsgAdapter adapter;

    /**
     * 用于存放获取到的数据
     */
    private List<SystemMsgBean.ListBean> datas;
    /**
     * 点击刷新布局控件
     */
    @ViewInject(R.id.swiplayout)
    private SwipeRefreshLayout swipeRefreshLayout;

    /**
     * list列表
     */
    @ViewInject(R.id.dish_list)
    private RecyclerView dish_list;



    @Override
    public void initView() {
        LittleUtils.setsimpletitlebar(this, "系统消息");

        datas = new ArrayList<>();
        adapter = new SystemMsgAdapter(this, datas, R.layout.item_system_msg);
        mlayoutManager = new LinearLayoutManager(this);//布局模式为listview方式
        dish_list.setLayoutManager(mlayoutManager);
        dish_list.setAdapter(adapter);

        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                getData();
            }
        });

    }

    @Override
    public void initEvent() {

    }

    @Override
    public void initData() {
        getData();
    }

    public void getData() {
        HashMap<String, String> hashMap = new HashMap<String, String>();
           hashMap.put("uid", Config.getUserId());
           hashMap.put("num", "50");
           hashMap.put("page", "0");
        new BaseInternet().getData_Get(URLString.SYSTEM_MSG, hashMap, SystemMsgBean.class, new SystemMsgEvent<SystemMsgBean>(), true,true);
    }

    @EventAnnotation
    public void SystemMsgEvent(SystemMsgEvent<SystemMsgBean> event) {
        swipeRefreshLayout.setRefreshing(false);
        switch (event.getCode()) {
            case 200:
                datas.clear();
                datas.addAll(event.getData().getList());
                adapter.notifyDataSetChanged();
                break;
            default:
                SN.SnackShow(dish_list,event.getMsg());
                break;
        }
    }

}
